/*  Copyright (C) 2013   Divya Muthyala & Meenal Nitin Honap.

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>. */

package com.herps;

import com.herps.navigation.NavigationBar;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

public class OrganismDetails extends Activity {
	
	private HerpDetails selectedOrganism;
	private TextView commonNameTv;
	private TextView groupTv;
	private TextView familyTv;
	private TextView genusTv, epithetTv;
	RelativeLayout myLayout;
	private ImageView imageView;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		myLayout = new RelativeLayout(this);
		NavigationBar nb = new NavigationBar(this);
		nb.setLeftBarButton("SNFCHerp List");
		nb.setRightBarButton("Observe", false);
		nb.setBarTitle("");
		
		nb.setId(0);
		NavigationBar.NavigationBarListener nbl = new NavigationBar.NavigationBarListener() {
		    @Override
		    public void OnNavigationButtonClick(int which) {
		    	switch(which){
		    	case 0:
		    		
		    		Intent intent = new Intent();
	                intent.setClass(OrganismDetails.this, SNFCHerpList.class);
	                startActivity(intent);
		    		
		    	break;
		    	case 1:
		    		//Toast.makeText(getApplicationContext(), "msg msg", Toast.LENGTH_SHORT).show();
		    		Intent intent1 = new Intent(getParent(), ObserveDetails.class);
		    		intent1.putExtra("com.herps.HerpDetails", selectedOrganism);
		    		View view = HerpsActivityGroup.group.getLocalActivityManager()
		              .startActivity("ObserveDetails", intent1
		              .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
		              .getDecorView();
		        	//startActivity(i);
		    	//	Toast.makeText(this, "You clicked " + selectedItem.getCommonName(), Toast.LENGTH_SHORT).show();
		        	HerpsActivityGroup.group.replaceView(view);
	              //  intent1.setClass(OrganismDetails.this, ObserveDetails.class);
	             //   startActivity(intent1);
		    		break;
		    	default:
		    		break;
		    	}
		    }
		
		};
		
		
		
	    nb.setNavigationBarListener(nbl);
		
		RelativeLayout.LayoutParams nbParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
		nbParams.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE);
		myLayout.addView(nb,nbParams);	
		
		RelativeLayout.LayoutParams detailsParam = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
		detailsParam.addRule(RelativeLayout.ALIGN_TOP,-1);
		myLayout.addView(LayoutInflater.from(this).inflate(R.layout.organismdetail, null),detailsParam);
		
		setContentView(myLayout);
		Bundle b = getIntent().getExtras();
		if(b.getParcelable("com.herps.HerpDetails") != null){
		 	selectedOrganism =
	        	b.getParcelable("com.herps.HerpDetails");
		}	
		
		if(selectedOrganism != null){
//			commonNameTv = (TextView) findViewById(R.id.commonNameTextView);
//			commonNameTv.setText(selectedOrganism.getCommonName());
//			groupTv = (TextView) findViewById(R.id.groupTextView);
//			groupTv.setText(selectedOrganism.getGroup());
			View detailsView = myLayout.getChildAt(1);
			commonNameTv = (TextView) detailsView.findViewById(R.id.commonNameTextView);
			commonNameTv.setText(selectedOrganism.getCommonName());
			//groupTv = (TextView)  detailsView.findViewById(R.id.groupTextView);
			//groupTv.setText(selectedOrganism.getGroup());
			genusTv = (TextView)  detailsView.findViewById(R.id.genusTextView);
			genusTv.setText(selectedOrganism.getGenus() + " " + selectedOrganism.getEpithet());
			
			//epithetTv = (TextView)  detailsView.findViewById(R.id.epithetTextView);
			//epithetTv.setText(selectedOrganism.getEpithet());
			
			familyTv = (TextView)  detailsView.findViewById(R.id.familyTextView);
			familyTv.setText(selectedOrganism.getFamily());
			
			imageView = (ImageView) detailsView.findViewById(R.id.imageView1);
			String imageName = selectedOrganism.getGenus() + "_" + selectedOrganism.getEpithet();
        	imageName = imageName.toLowerCase();
        	imageView.setImageResource(this.getResources().getIdentifier(imageName,"drawable",this.getPackageName()));
			
		}
		
		
		//setContentView(R.layout.organismdetail);
		
	
	}

	
	
}
